package com.huirui.server.controller.admin;

import com.huirui.server.pojo.dto.NewcomerAreaProductDto;
import com.huirui.server.pojo.result.PageResult;
import com.huirui.server.pojo.result.Result;
import com.huirui.server.pojo.vo.NewcomerAreaProductVo;
import com.huirui.server.service.NewcomerAreaProductService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController("adminNewcomerArea")
@RequestMapping("/admin/newcomer/area")
@Slf4j
@Validated
@Tag(name = "新客专区商品管理", description = "新客专区商品管理")
public class NewcomerAreaController {

    @Resource
    private NewcomerAreaProductService newcomerAreaProductService;

    @PostMapping("/add/product")
    @Operation(summary = "添加新客专享商品")
    public Result<Void> addProduct(@RequestBody @Validated NewcomerAreaProductDto newcomerAreaProductDto) {
        newcomerAreaProductService.addProduct(newcomerAreaProductDto);
        return Result.success();
    }

    @GetMapping("/list")
    @Operation(summary = "获取商品列表")
    public Result<PageResult<NewcomerAreaProductVo>> listNewcomerProduct(
            @RequestParam(value = "keyword", required = false)
            String keyword,
            Long page,
            Long pageSize
    ) {
        PageResult<NewcomerAreaProductVo> res = newcomerAreaProductService.listNewcomerProduct(keyword, page, pageSize);
        return Result.success(res);
    }

    @PutMapping("/update/product")
    @Operation(summary = "更新新客专享商品信息")
    public Result<Void> updateProduct(@RequestBody @Validated NewcomerAreaProductDto newcomerAreaProductDto) {
        newcomerAreaProductService.updateProduct(newcomerAreaProductDto);
        return Result.success();
    }

    @DeleteMapping("/delete/product")
    @Operation(summary = "删除商品")
    public Result<Void> deleteProduct(@RequestParam("productId") Long productId) {
        newcomerAreaProductService.deleteProduct(productId);
        return Result.success();
    }


}
